﻿using AiMoWindows.CodeScripts;
namespace AiMoWindows.MainActions.ScriptActions.SubActions
{
    /// <summary>
    /// 手动添加Code的逻辑在这类组织
    /// </summary>
    class AppendAdditionCodeAction(ActionsController actions, ScriptManager scriptManager)
    {
        readonly ActionsController actions = actions;
        readonly ScriptManager scriptManager = scriptManager;
        public async void AddLoop()
        {
            if (scriptManager.CompileMode != Mode.ScriptComplileMode.RhinoScript) return;
            // 先同步到后台
            bool re = await actions.SyncAction.SendEditorScriptToBack();
            if (re)
            {
                // 后台添加循环
                scriptManager.AppendLoopCode();
                // 同步AiMoScript修改到前台
                await actions.SyncAction.BringBackScriptToEditor();
            }
        }
        public async void AddOnLoad()
        {
            if (scriptManager.CompileMode != Mode.ScriptComplileMode.RhinoScript) return;
            // 先同步到后台
            bool re = await actions.SyncAction.SendEditorScriptToBack();
            if (re)
            {
                // 后台添加加载时执行
                scriptManager.AppendOnLoadCode();
                // 同步AiMoScript修改到前台
                await actions.SyncAction.BringBackScriptToEditor();
            }
        }
    }
}
